package com.ithiema.reggie.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.sql.SQLIntegrityConstraintViolationException;
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R doHandler(SQLIntegrityConstraintViolationException e){
      log.error("异常信息:{}",e.getMessage());
      if (e.getMessage().contains("Duplicate entry")){
          String msg = e.getMessage().split("")[2]+"已存在";
          return R.error(msg);

      }return R.error("未知错误");
    }
}
